import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import routes from './views'

const router  = new VueRouter({
  routes: [
    ...routes,
    {
      path: '/',
      redirect: '/home'
    }
  ]
})
router.beforeEach((to, Form, next) => {
  if(to.meta.isAuth) {
    if(localStorage.getItem('token')) return next();
    return next('/tologin')
  }
  next()
}) 
export default router